<template>
  <!-- 专利 -->
  <el-descriptions :column="2" size="large">
    <el-descriptions-item label-class-name="right-align" label='成果来源'>
      <span class="text--info subtext" v-if='rewardsInfo.projectId'>项目</span>
      <span class="text--info subtext" v-else>非项目</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='获奖项目'>
      <span class="text--info subtext">{{rewardsInfo.rewardProject}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='所属项目' v-if='rewardsInfo?.projectId'>
      <span class="text--info subtext">{{projectInfo?.projectName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='项目编号' v-if='rewardsInfo?.projectId'>
      <span class="text--info subtext">{{projectInfo.projectCode}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='奖项类别'>
      <span class="text--info subtext">{{model.rewardsTypes[rewardsInfo?.rewardsType]}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='奖励级别'>
      <span class="text--info subtext">{{model.rewardsLevels[rewardsInfo?.rewardsLevel]}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='获奖时间'>
      <span class="text--info subtext">{{rewardsInfo.awardsYear}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='所属公司主体'>
      <span class="text--info subtext">{{rewardsInfo.companyEntityName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='颁奖单位'>
      <span class="text--info subtext">{{rewardsInfo?.grantAwardsDept}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='项目牵头单位名称'>
      <span class="text--info subtext">{{rewardsInfo?.leadDept}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='获奖单位'>
      <span class="text--info subtext" v-for="item in rewardsInfo.deptList" :key="item.id">{{item.bizName}}&nbsp;&nbsp;</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='上传文档'>
      <div v-if="rewardsInfo.attachmentList?.length" class="file-wrap">
        <p
          class="text--info download-link subtext"
          v-for="(obj, index) in rewardsInfo?.attachmentList"
          :key="index"
          @click.prevent="handlePreview(obj)"
        >
          <el-link :underline="false" icon="el-icon-folder">{{ obj?.fileName }}&nbsp;&nbsp;</el-link>
        </p>
      </div>
      <div class="text--info subtext file-wrap" v-else> - </div>
    </el-descriptions-item>
  </el-descriptions>
</template>

<script lang="ts" setup>
import {ref, watch,reactive} from "vue";
import { getRewardsById } from "/@/api/document";
const props = defineProps({
  projectInfo: {
    type: Object,
    default:()=>{}
  },
});
let info = ref({});
let rewardsInfo = ref({})
let model = reactive({
  rewardsLevels: {
    0:"特等奖",
    1:"一等奖",
    2:"二等奖",
    3:"其他",
    4:"不分等级"
  },
  rewardsTypes: {
    1: "国家最高科学技术奖",
    2: "国家自然科学奖",
    3: "国家技术发明奖",
    4: "国家科学技术进步奖",
    5: "国际科学技术合作奖",
    6: "省部级科技奖",
    7: "其他科技奖"
  }
})

const getData = async id => {
  const { data,code } = await getRewardsById(id);
  if(code == 200){
    rewardsInfo.value = data;
    rewardsInfo.value.attachmentList = JSON.parse(data.attachment);
  }
};

const handlePreview = (item: any) => {
  if (item.response) {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item?.response.data.uuidFile}&fileName=${item?.response.data.fileName}`
    );
  } else {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item.uuidFile}&fileName=${item.fileName}`
    );
  }
};

watch(
  () => props.projectInfo,
  newvalue => {
    info.value = newvalue;
    const kyId = newvalue.kyId
    if(kyId){
      getData(kyId)
    }
  },
  { immediate: true }
);
</script>

<style lang="scss" scoped>
  .file-wrap{
    display: inline-block;
    vertical-align: top
  }
</style>
